package com.hxd.otc.module.my.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.my.bean.GoogleCreateBean;
import com.hxd.otc.module.my.contract.BindGoogleCodeContract;
import com.hxd.otc.module.my.model.UserModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.widget.BlocksToast;

public class BindGoogleCodePresenter extends BasePresenter<BindGoogleCodeContract.IView> implements BindGoogleCodeContract.IPresenter {

    private final UserModel mUserModel;

    public BindGoogleCodePresenter(BindGoogleCodeContract.IView iView) {
        super(iView);
        mUserModel = UserModel.getInstance();
    }

    @Override
    public void getPhoneVerCode() {
        mUserModel.sendExValidTypeMobileSms("bander_google", new BaseObserver<String>() {

            @Override
            public void onNext(String msg, String o) {
                mView.startPhoneCountdown();
            }

            @Override
            public void onError(int errType, String errMessage) {
                mView.showToast(errMessage);
            }

        }, mView.<BaseBean<String>>bindAutoDispose());
    }

    @Override
    public void sendEmailVerCode() {
        mUserModel.sendExValidTypeEmail("bander_google_mail", new BaseObserver<String>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull String s) {
                mView.startPhoneCountdown();
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                BlocksToast.get().showToast(errMessage);
            }
        }, mView.<BaseBean<String>>bindAutoDispose());
    }

    @Override
    public void getGoogleCode() {
        mUserModel.getGoogleCode(new BaseObserver<GoogleCreateBean>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull GoogleCreateBean googleCreateBean) {
                mView.getGoogleCodeSuccess(googleCreateBean);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.getGoogleCodeFail(errMessage);
            }
        }, mView.<BaseBean<GoogleCreateBean>>bindAutoDispose());
    }

    @Override
    public void bindGoogleCode(String googleCode, String googleSecret, String phoneCode) {
        mUserModel.bindGoogleCode(googleCode, googleSecret, phoneCode, new BaseObserver<String>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull String s) {
                mView.bindGoogleCodeSuccess();
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.bindGoogleCodeFail(errMessage);
            }
        }, mView.<BaseBean<String>>bindAutoDispose());
    }
}
